package com.xiaozhameng.bootstudy.all.txtest;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaozhameng.bootstudy.dao.UserDao;
import com.xiaozhameng.bootstudy.entity.UserEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * 事务测试
 */
@Service("txUserServiceCC")
public class TxUserServiceCCImpl extends ServiceImpl<UserDao, UserEntity> implements IService<UserEntity> {


    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void methodCC() {
        // 保存一个方法
        this.save(this.buildUser("CC1"));
    }


    /**
     * 构建一个user 对象
     */
    private UserEntity buildUser(String userName) {
        UserEntity entity = new UserEntity();
        entity.setName(userName);
        entity.setAddress("测试-cc");
        entity.setBirthday(new Date());

        return entity;
    }


}
